<template>
	<!-- 登录页 -->
	<view id="login">
		<view class="form">
			<view class="item">
				<view class="header">
					<image :src="require('../../static/login/user.png')" mode="aspectFit"></image>
					<text>帐号</text>
				</view>
				<input type="text" placeholder-class="loginPlace" v-model="user.username" placeholder="请输入帐号" />
			</view>
			<view class="item">
				<view class="header">
					<image :src="require('../../static/login/pwd.png')" mode="aspectFit"></image>
					<text>密码</text>
				</view>
				<input type="password" placeholder-class="loginPlace" v-model="user.password" placeholder="请输入密码" confirm-type="done" />
			</view>
			<button type="default" @click="submit">登录</button>
			<view class="loginAgreen"><view @click="agreeCheck=!agreeCheck" class="loginCheck" :class="[agreeCheck?'checked':'']"></view>登录即代表同意<text @click="navTo(1)">用户协议</text>与<text @click="navTo(2)">隐私政策</text></view>
		</view>
		<!-- <view class="loginWarn">温馨提示：目前只对合作院校学生开放哦~</view> -->
	</view>
</template>

<script>
export default {
	data() {
		return {
			user: {
				username: '',
				password: '',
				clientId: '',
				phoneBrand:'',//手机品牌
				phoneModel:'',//手机型号
				phoneSystemVersion:'',//手机OS
			},
			agreeCheck:false//选中框选中
		};
	},
	onLoad() {
		// #ifdef APP-PLUS
		this.user.clientId = plus.push.getClientInfo().clientid;
		const sysInfo=uni.getSystemInfoSync()
		this.user.phoneBrand=sysInfo.brand
		this.user.phoneModel=sysInfo.model
		this.user.phoneSystemVersion=sysInfo.platform +' '+sysInfo.system
		// #endif
	},
	methods: {
		submit() {
			if(!this.agreeCheck){
				uni.showToast({
					icon: 'none',
					title:'请同意用户协议及隐私政策'
				})
				return
			}
			const { username, password } = this.user;
			if (!username.length || !password.length) {
				uni.showToast({
					icon: 'none',
					title: '用户名或密码不能为空！'
				});
				return;
			}
			uni.showLoading({
				title: '登录中...'
			});
			this.login(this.user)
				.then(res => {
					uni.hideLoading();
					uni.showToast({
						title: '登录成功!',
						type: 'success',
						complete() {
							uni.setStorageSync('todayClick','')
							setTimeout(function(){
								uni.switchTab({
									url: '../home/home'
								});
							},1000)
						}
					});
				})
				.catch(err => {
					console.log(err);
					uni.hideLoading();
					uni.showModal({
						content: '用户名或密码错误，请重新输入！',
						showCancel: false
					});
				});
		},
		//跳转方式
		navTo(type){
			uni.navigateTo({
				url:'./agreen/agreen?type='+type
			})
		}
	}
};
</script>

<style scoped lang="scss">
#login {
	background-image: url('../../static/login/bg.png');
	width: 100%;
	height: 100%;
	background-size: 100%;
	padding-top: 548upx;
	background-repeat: no-repeat;
	color: #363940;
	.form {
		width: 690upx;
		padding: 64upx 94upx 83upx 40upx;
		margin: 0 auto;
		height: 636upx;
		opacity: 0.9;
		background: #ffffff;
		border-radius: 50upx;
		box-shadow: 0px 10upx 18upx 0px rgba(0, 0, 0, 0.08);
		button {
			margin-left: 60upx;
			border: none;
			line-height: 80upx;
			background: $linear-bg;
			border-radius: 40upx;
			font-size: 32upx;
			color: white;
		}
	}
}
.item {
	display: flex;
	flex-direction: column;
	margin-bottom: 52upx;
	.header {
		font-size: 32upx;
		font-weight: 400;
		line-height: 40upx;
		display: inherit;
		align-items: center;
		image {
			width: 40upx;
			height: 40upx;
			margin-right: 20upx;
		}
	}
	input {
		border-bottom: 1px solid #e6e6e6;
		margin-left: 60upx;
		height: 70upx;
		padding-top: 10upx;
		font-size: 26upx;
	}
}
.loginPlace{
	color: #A6A6A6;
}
.loginWarn{
	font-size: 30upx;
	color: #919499;
	position: absolute;
	bottom: 60upx;
	text-align: center;
	width: 100%;
}
.loginAgreen{
	text-align: center;
	color: #919499;
	font-size: 26upx;
	margin-top: 52upx;
	display: flex;
	justify-content: center;
	align-items: center;
	text{
		color: #F45C4B;
		padding: 0 5upx;
	}
	.checked{
		background:#F45C4B url(../../static/login/login_check.png) no-repeat center center;
		background-size: 100% 100%;
		border: 1px solid #F45C4B!important;
	}
	.loginCheck{
		width: 26upx;
		height: 26upx;
		border:1px solid #babbbf;
		border-radius: 26upx;
		margin-right: 11upx;
	}
}
</style>
